package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.service.CommonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author bairimengchang
 * @version 1.0
 * @project sky-take-out
 * @description 通用控制器
 * @date 2024/08/06 17:54:03
 */
@RestController
@RequestMapping("/admin/common")
@Slf4j
@Api(tags = "通用相关接口")
public class CommonController {

    @Autowired
    private CommonService commonService;

    /**
     * 文件上传
     * @param file 要上传的文件
     * @return 对应的阿里OSS的访问url地址，或者错误信息结果对象
     */
    @PostMapping("/upload")
    @ApiOperation(value = "文件上传")
    public Result<String> upload(@RequestParam("file") MultipartFile file) {
        log.info("文件上传的内容:{}", file.getOriginalFilename());
        String filePath = commonService.upload(file);
        return Result.success(filePath);
    }

}
